2015-08-30.sql 203 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. 
  2. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotFilmSelection')
  3. BEGIN
  4. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotFilmSelection
  5. END
  6. GO
  7. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotFilmSelection]'))
  8. EXEC dbo.sp_executesql @statement = N'
  9. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotFilmSelection]
  10. AS
  11. SELECT
  12. tb_ErpOrder.ID,
  13. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  14. dbo.tb_ErpOrder.Ord_Number,
  15. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  16. Ordv_DigitalNumber,
  17. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  18. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  19. Cus_Name AS 客户姓名,
  20. Cus_Name_py AS 客户拼音,
  21. Cus_Sex_cs AS 客户性别,
  22. Cus_Telephone AS 客户电话,
  23. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  24. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  25. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  26. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  27. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  28. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  29. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  30. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  31. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  32. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  33. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName) AS 选片师,
  34. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间,
  35. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatcher) AS 录入,
  36. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatchTime)) AS 录入时间,
  37. (SELECT COUNT(Ordv_ViceNumber) AS Expr1
  38. FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1
  39. WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  40. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  41. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  42. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  43. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  44. '
  45. GO
  46. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotLookDesign')
  47. BEGIN
  48. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotLookDesign
  49. END
  50. GO
  51. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotLookDesign]'))
  52. EXEC dbo.sp_executesql @statement = N'
  53. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotLookDesign]
  54. AS
  55. SELECT tb_ErpOrder.ID,
  56. dbo.tb_ErpOrder.Ord_DividedShop,
  57. Ord_Type,
  58. dbo.tb_ErpOrder.Ord_Number,
  59. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  60. Ordv_DigitalNumber,
  61. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  62. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  63. Cus_Name AS 客户姓名,
  64. Cus_Name_py AS 客户拼音,
  65. Cus_Sex_cs AS 客户性别,
  66. Cus_Telephone AS 客户电话,
  67. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  68. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  69. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  70. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  71. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  72. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  73. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  74. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  75. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName) AS 看设计师,
  76. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间,
  77. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatcher) AS 录入者,
  78. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatchTime) AS 录入时间,
  79. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  80. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  81. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  82. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  83. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  84. '
  85. GO
  86. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotPhotographed')
  87. BEGIN
  88. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotPhotographed
  89. END
  90. GO
  91. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotPhotographed]'))
  92. EXEC dbo.sp_executesql @statement = N'
  93. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotPhotographed]
  94. AS
  95. SELECT tb_ErpOrder.ID,
  96. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  97. dbo.tb_ErpOrdersPhotography.ID AS PID,
  98. dbo.tb_ErpOrder.Ord_Number,
  99. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  100. Ordv_DigitalNumber,
  101. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  102. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  103. Cus_Name AS 客户姓名,
  104. Cus_Name_py AS 客户拼音,
  105. Cus_Sex_cs AS 客户性别,
  106. Cus_Telephone AS 客户电话,
  107. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  108. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  109. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  110. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  111. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  112. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrder.Ord_CreateDateTime)) AS 订单日期,
  113. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  114. dbo.fn_CheckPhotographyStatus(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus) AS 拍摄状态,
  115. dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime) AS 摄影时间,
  116. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师,
  117. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理,
  118. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师,
  119. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理,
  120. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师,
  121. dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 备注,
  122. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON
  123. tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  124. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  125. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  126. dbo.tb_ErpOrdersPhotography ON
  127. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber
  128. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  129. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  130. '
  131. GO
  132. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotPickup')
  133. BEGIN
  134. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotPickup
  135. END
  136. GO
  137. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotPickup]'))
  138. EXEC dbo.sp_executesql @statement = N'
  139. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotPickup]
  140. AS
  141. SELECT
  142. tb_ErpOrder.ID,
  143. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  144. dbo.tb_ErpOrder.Ord_Number,
  145. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  146. Ordv_DigitalNumber,
  147. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  148. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  149. Cus_Name AS 客户姓名,
  150. Cus_Name_py AS 客户拼音,
  151. Cus_Sex_cs AS 客户性别,
  152. Cus_Telephone AS 客户电话,
  153. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  154. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  155. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  156. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  157. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  158. CASE WHEN Ord_Type = ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  159. tb_ErpOrderProductList.ID AS PPID,
  160. OPlist_ProdName AS 商品名称,
  161. dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 取件状态,
  162. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成状态,
  163. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 取件日期,
  164. OPlist_ReservationTakeName AS 取件人,
  165. dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急,
  166. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 加急日期
  167. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  168. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  169. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  170. Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber
  171. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  172. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  173. '
  174. GO
  175. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotSelectDress')
  176. BEGIN
  177. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotSelectDress
  178. END
  179. GO
  180. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotSelectDress]'))
  181. EXEC dbo.sp_executesql @statement = N'
  182. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotSelectDress]
  183. AS
  184. SELECT
  185. tb_ErpOrder.ID,
  186. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  187. dbo.tb_ErpOrder.Ord_Number,
  188. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  189. Ordv_DigitalNumber,
  190. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  191. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  192. Cus_Name AS 客户姓名,
  193. Cus_Name_py AS 客户拼音,
  194. Cus_Sex_cs AS 客户性别,
  195. Cus_Telephone AS 客户电话,
  196. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  197. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  198. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  199. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  200. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  201. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  202. dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态,
  203. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName) AS 选礼服师,
  204. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime) AS 选礼服时间,
  205. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatcher) AS 安排人,
  206. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatchTime) AS 安排时间,
  207. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  208. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  209. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  210. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  211. '
  212. GO
  213. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotWedding')
  214. BEGIN
  215. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotWedding
  216. END
  217. GO
  218. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotWedding]'))
  219. EXEC dbo.sp_executesql @statement = N'
  220. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotWedding]
  221. AS
  222. SELECT tb_ErpOrder.ID,
  223. dbo.tb_ErpOrder.Ord_DividedShop,
  224. dbo.tb_ErpWeddingService.ID AS WID,
  225. Ord_Type,
  226. dbo.tb_ErpOrder.Ord_Number,
  227. 0 AS Ordv_DigitalNumber,
  228. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  229. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  230. Cus_Name AS 客户姓名,
  231. Cus_Name_py AS 客户拼音,
  232. Cus_Sex_cs AS 客户性别,
  233. Cus_Telephone AS 客户电话,
  234. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  235. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  236. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  237. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  238. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  239. dbo.tb_ErpWeddingService.Ws_ProdName AS 婚庆内容,
  240. dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态,
  241. dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDate) AS 婚庆日期,
  242. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1,
  243. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2,
  244. dbo.tb_ErpWeddingService.Ws_Remark AS 服务备注,
  245. (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  246. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  247. dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number
  248. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  249. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  250. '
  251. GO
  252. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainFilmSelection')
  253. BEGIN
  254. DROP VIEW [dbo].BView_CameraControlBookMainFilmSelection
  255. END
  256. GO
  257. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainFilmSelection]'))
  258. EXEC dbo.sp_executesql @statement = N'
  259. CREATE VIEW [dbo].[BView_CameraControlBookMainFilmSelection]
  260. AS
  261. SELECT
  262. tb_ErpOrder.ID,
  263. dbo.tb_ErpOrder.Ord_DividedShop,
  264. Ord_Type,
  265. dbo.tb_ErpOrder.Ord_Number,
  266. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  267. Ordv_DigitalNumber,
  268. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  269. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  270. Cus_Name AS 客户姓名,
  271. Cus_Sex_cs AS 客户性别,
  272. Cus_Telephone AS 客户电话,
  273. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  274. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  275. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  276. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  277. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  278. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  279. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  280. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  281. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  282. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName) AS 选片师,
  283. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间,
  284. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 选片时间查询,
  285. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatcher) AS 安排人,
  286. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatchTime)) AS 安排时间,
  287. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  288. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  289. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  290. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  291. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  292. '
  293. GO
  294. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLookDesign')
  295. BEGIN
  296. DROP VIEW [dbo].BView_CameraControlBookMainLookDesign
  297. END
  298. GO
  299. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLookDesign]'))
  300. EXEC dbo.sp_executesql @statement = N'
  301. CREATE VIEW [dbo].[BView_CameraControlBookMainLookDesign]
  302. AS
  303. SELECT
  304. tb_ErpOrder.ID,
  305. dbo.tb_ErpOrder.Ord_DividedShop,
  306. Ord_Type,
  307. dbo.tb_ErpOrder.Ord_Number,
  308. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  309. Ordv_DigitalNumber,
  310. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  311. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  312. Cus_Name AS 客户姓名,
  313. Cus_Sex_cs AS 客户性别,
  314. Cus_Telephone AS 客户电话,
  315. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  316. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  317. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  318. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  319. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  320. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  321. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName) AS 看设计师,
  322. dbo.fn_CheckDateTime(Ordv_ReservationLookDesignTime) AS 看设计时间,
  323. Ordv_ReservationLookDesignTime AS 看设计时间查询,
  324. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatcher) AS 安排人,
  325. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatchTime)) AS 安排时间,
  326. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  327. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  328. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  329. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  330. '
  331. GO
  332. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed')
  333. BEGIN
  334. DROP VIEW [dbo].BView_CameraControlBookMainPhotographed
  335. END
  336. GO
  337. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed]'))
  338. EXEC dbo.sp_executesql @statement = N'
  339. CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed]
  340. AS
  341. SELECT tb_ErpOrder.ID,
  342. dbo.tb_ErpOrder.Ord_DividedShop,
  343. Ord_Type,
  344. dbo.tb_ErpOrdersPhotography.ID AS VID,
  345. dbo.tb_ErpOrder.Ord_Number,
  346. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  347. Ordv_DigitalNumber,
  348. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  349. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  350. Cus_Name AS 客户姓名,
  351. Cus_Sex_cs AS 客户性别,
  352. Cus_Telephone AS 客户电话,
  353. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  354. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  355. (Ord_SeriesPrice - (Case when (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) is null then 0 else (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) end) + (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number)) AS 欠款,
  356. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  357. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  358. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  359. dbo.fn_CheckPhotographyStatus(Ordpg_PhotographyStatus) AS 拍摄状态,
  360. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 摄影时间,
  361. Ordpg_ReservationPhotographyTime AS 摄影时间查询,
  362. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师,
  363. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理,
  364. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师,
  365. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理,
  366. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师,
  367. dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 录入备注,
  368. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Dispatcher) AS 安排人,
  369. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_DispatchTime)) AS 安排时间,
  370. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN
  371. dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  372. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  373. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  374. dbo.tb_ErpOrdersPhotography ON
  375. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber
  376. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  377. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  378. '
  379. GO
  380. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPickup')
  381. BEGIN
  382. DROP VIEW [dbo].BView_CameraControlBookMainPickup
  383. END
  384. GO
  385. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPickup]'))
  386. EXEC dbo.sp_executesql @statement = N'
  387. CREATE VIEW [dbo].[BView_CameraControlBookMainPickup]
  388. AS
  389. SELECT
  390. dbo.tb_ErpOrder.ID,
  391. dbo.tb_ErpOrder.Ord_DividedShop,Ord_Type,
  392. tb_ErpOrderProductList.ID AS PID,
  393. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  394. Ordv_DigitalNumber,
  395. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  396. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  397. Cus_Name AS 客户姓名,
  398. Cus_Sex_cs AS 客户性别,
  399. Cus_Telephone AS 客户电话,
  400. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  401. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  402. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  403. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  404. CASE WHEN Ord_Type = ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  405. dbo.tb_ErpOrderProductList.OPlist_ProdName AS 商品名称,
  406. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 取件时间,
  407. OPlist_ReservationTakeTime AS 取件时间查询,
  408. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderProductList.OPlist_PickupName) AS 取件人,
  409. dbo.fn_CheckTakePiecesStatus(dbo.tb_ErpOrderProductList.OPlist_PickupStatus) AS 取件状态,
  410. dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderProductList.OPlist_CompletedStatus) AS 完成状态,
  411. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderProductList.OPlist_ArrangeNmae) AS 安排人,
  412. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_ArrangeTime)) AS 安排时间
  413. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  414. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  415. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  416. dbo.tb_ErpOrderProductList ON
  417. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrderProductList.OPlist_ViceNumber
  418. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  419. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'') AND
  420. (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  421. '
  422. GO
  423. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainSelectDress')
  424. BEGIN
  425. DROP VIEW [dbo].BView_CameraControlBookMainSelectDress
  426. END
  427. GO
  428. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainSelectDress]'))
  429. EXEC dbo.sp_executesql @statement = N'
  430. CREATE VIEW [dbo].[BView_CameraControlBookMainSelectDress]
  431. AS
  432. SELECT
  433. tb_ErpOrder.ID,
  434. dbo.tb_ErpOrder.Ord_DividedShop,
  435. Ord_Type,
  436. dbo.tb_ErpOrder.Ord_Number,
  437. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  438. Ordv_DigitalNumber,
  439. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  440. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  441. Cus_Name AS 客户姓名,
  442. Cus_Sex_cs AS 客户性别,
  443. Cus_Telephone AS 客户电话,
  444. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  445. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  446. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  447. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  448. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  449. dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态,
  450. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName) AS 选礼服师,
  451. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime)) AS 选礼服时间,
  452. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间查询,
  453. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatcher) AS 安排人,
  454. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatchTime)) AS 安排时间,
  455. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  456. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  457. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  458. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  459. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  460. '
  461. GO
  462. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainWedding')
  463. BEGIN
  464. DROP VIEW [dbo].BView_CameraControlBookMainWedding
  465. END
  466. GO
  467. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainWedding]'))
  468. EXEC dbo.sp_executesql @statement = N'
  469. CREATE VIEW [dbo].[BView_CameraControlBookMainWedding]
  470. AS
  471. SELECT
  472. tb_ErpOrder.ID,
  473. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  474. dbo.tb_ErpWeddingService.Ws_Type,
  475. dbo.tb_ErpWeddingService.ID AS VID,
  476. dbo.tb_ErpOrder.Ord_Number,
  477. 0 AS Ordv_DigitalNumber,
  478. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  479. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  480. Cus_Name AS 客户姓名,
  481. Cus_Sex_cs AS 客户性别,
  482. Cus_Telephone AS 客户电话,
  483. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  484. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  485. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  486. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  487. dbo.tb_ErpWeddingService.Ws_ProdName AS 服务内容,
  488. dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态,
  489. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 服务日期,
  490. Ws_WeddingDate AS 服务日期查询,
  491. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1,
  492. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2,
  493. dbo.tb_ErpWeddingService.Ws_Remark AS 服务备注,
  494. (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  495. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number
  496. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  497. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  498. '
  499. GO
  500. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDesign')
  501. BEGIN
  502. DROP VIEW [dbo].BView_DoorCityDesign
  503. END
  504. GO
  505. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDesign]'))
  506. EXEC dbo.sp_executesql @statement = N'
  507. CREATE VIEW [dbo].[BView_DoorCityDesign]
  508. AS
  509. SELECT
  510. tb_ErpOrder.ID,
  511. dbo.tb_ErpOrder.Ord_DividedShop,
  512. dbo.tb_ErpOrder.Ord_Number,
  513. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  514. Ordv_DigitalNumber,
  515. Ord_Type,
  516. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  517. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  518. Cus_Name AS 客户姓名,
  519. Cus_Name_py AS 客户拼音,
  520. Cus_Sex_cs AS 客户性别,
  521. Cus_Telephone AS 客户电话,
  522. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  523. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  524. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  525. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  526. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  527. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  528. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  529. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  530. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  531. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  532. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  533. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  534. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  535. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  536. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修日期,
  537. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  538. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  539. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  540. dbo.tb_ErpOrderDigital.Ordv_DesignerTime AS 设计查询日期,
  541. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  542. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  543. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  544. dbo.tb_ErpOrderDigital.Ordv_LookDesignClaim AS 看设计要求,
  545. (SELECT COUNT(Ordv_ViceNumber) AS Expr1
  546. FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1
  547. WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  548. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  549. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  550. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  551. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  552. '
  553. GO
  554. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrange')
  555. BEGIN
  556. DROP VIEW [dbo].BView_DoorCityDigitalArrange
  557. END
  558. GO
  559. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrange]'))
  560. EXEC dbo.sp_executesql @statement = N'
  561. CREATE VIEW [dbo].[BView_DoorCityDigitalArrange]
  562. AS
  563. SELECT
  564. tb_ErpOrder.ID,
  565. dbo.tb_ErpOrder.Ord_DividedShop,
  566. dbo.tb_ErpOrder.Ord_Number,
  567. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  568. Ordv_DigitalNumber,
  569. Ord_Type,
  570. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  571. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  572. Cus_Name AS 客户姓名,
  573. Cus_Name_py AS 客户拼音,
  574. Cus_Sex_cs AS 客户性别,
  575. Cus_Telephone AS 客户电话,
  576. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  577. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  578. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  579. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  580. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  581. --dbo.fn_GetPhotographerStatus(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 拍摄状态,
  582. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  583. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  584. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_EarlyRepairName <> '''' then Ordv_EarlyRepairName else Ordv_ReservationEarlyRepairName end)) AS 初修状态,
  585. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修日期,
  586. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_FilmSelectionName <> '''' then Ordv_FilmSelectionName else Ordv_ReservationFilmSelectionName end)) AS 选片状态,
  587. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期,
  588. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 选片查询日期,
  589. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_DesignerName <> '''' then Ordv_DesignerName else Ordv_ReservationDesignerName end)) AS 设计状态,
  590. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计日期,
  591. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_RefinementName <> '''' then Ordv_RefinementName else Ordv_ReservationRefinementName end)) AS 精修状态,
  592. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修日期,
  593. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_LookDesignName <> '''' then Ordv_LookDesignName else Ordv_ReservationLookDesignName end)) AS 看设计状态,
  594. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  595. dbo.tb_ErpOrderDigital.Ordv_LookDesignTime AS 看设计查询日期,
  596. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  597. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  598. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  599. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  600. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  601. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  602. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  603. '
  604. GO
  605. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityFilmSelection')
  606. BEGIN
  607. DROP VIEW [dbo].BView_DoorCityFilmSelection
  608. END
  609. GO
  610. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityFilmSelection]'))
  611. EXEC dbo.sp_executesql @statement = N'
  612. CREATE VIEW [dbo].[BView_DoorCityFilmSelection]
  613. AS
  614. SELECT
  615. tb_ErpOrder.ID,
  616. dbo.tb_ErpOrder.Ord_DividedShop,
  617. dbo.tb_ErpOrder.Ord_Number,
  618. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  619. Ordv_DigitalNumber,
  620. Ord_Type,
  621. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  622. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  623. Cus_Name AS 客户姓名,
  624. Cus_Name_py AS 客户拼音,
  625. Cus_Sex_cs AS 客户性别,
  626. Cus_Telephone AS 客户电话,
  627. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  628. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  629. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  630. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  631. dbo.tb_ErpOrder.Ord_PlusPickNumber AS 加挑张数,
  632. dbo.fn_GetPlusPickAmount(dbo.tb_ErpOrder.Ord_Number) AS 加挑金额,
  633. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  634. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  635. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  636. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  637. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  638. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 初修日期,
  639. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName) AS 选片师,
  640. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期,
  641. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 选片日期查询,
  642. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  643. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  644. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  645. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  646. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  647. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  648. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  649. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  650. '
  651. GO
  652. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityKePan')
  653. BEGIN
  654. DROP VIEW [dbo].BView_DoorCityKePan
  655. END
  656. GO
  657. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityKePan]'))
  658. EXEC dbo.sp_executesql @statement = N'
  659. CREATE VIEW [dbo].[BView_DoorCityKePan]
  660. AS
  661. SELECT
  662. tb_ErpOrder.ID,
  663. dbo.tb_ErpOrder.Ord_DividedShop,
  664. dbo.tb_ErpOrder.Ord_Number,
  665. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  666. Ordv_DigitalNumber,
  667. Ord_Type,
  668. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  669. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  670. Cus_Name AS 客户姓名,
  671. Cus_Name_py AS 客户拼音,
  672. Cus_Sex_cs AS 客户性别,
  673. Cus_Telephone AS 客户电话,
  674. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  675. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  676. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  677. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  678. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  679. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  680. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  681. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  682. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  683. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  684. dbo.fn_GetKePan(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 1) AS 刻盘次数,
  685. dbo.fn_GetKePan(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 2) AS 刻盘状态,
  686. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  687. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  688. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  689. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  690. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  691. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  692. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  693. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  694. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  695. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  696. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  697. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  698. '
  699. GO
  700. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotographed')
  701. BEGIN
  702. DROP VIEW [dbo].BView_DoorCityPhotographed
  703. END
  704. GO
  705. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotographed]'))
  706. EXEC dbo.sp_executesql @statement = N'
  707. CREATE VIEW [dbo].[BView_DoorCityPhotographed]
  708. AS
  709. SELECT
  710. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrdersPhotography.ID AS JID,
  711. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  712. Ordv_DigitalNumber,
  713. dbo.tb_ErpOrder.Ord_CustomerSource,
  714. dbo.tb_ErpOrder.Ord_PhotographyCategory, Ord_Type,
  715. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  716. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  717. Cus_Name AS 客户姓名,
  718. Cus_Name_py AS 客户拼音,
  719. Cus_Sex_cs AS 客户性别,
  720. Cus_Telephone AS 客户电话,
  721. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  722. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  723. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  724. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  725. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  726. dbo.fn_CheckOrderPhotographyStatus(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus) AS 拍摄状态,
  727. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Photographer) AS 摄影师,
  728. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 拍摄日期,
  729. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 拍摄日期查询,
  730. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant) AS 拍摄助理,
  731. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist) AS 化妆师,
  732. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_MakeupAssistant) AS 化妆助理,
  733. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision) AS 引导师,
  734. dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选衣状态,
  735. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  736. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  737. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  738. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  739. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  740. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1
  741. FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN
  742. dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON
  743. tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber
  744. WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  745. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  746. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  747. dbo.tb_ErpOrdersPhotography ON
  748. dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  749. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  750. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  751. '
  752. GO
  753. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrints')
  754. BEGIN
  755. DROP VIEW [dbo].BView_DoorCityPhotosPrints
  756. END
  757. GO
  758. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrints]'))
  759. EXEC dbo.sp_executesql @statement = N'
  760. CREATE VIEW [dbo].[BView_DoorCityPhotosPrints]
  761. AS
  762. SELECT
  763. tb_ErpOrder.ID,
  764. dbo.tb_ErpOrder.Ord_DividedShop,
  765. dbo.tb_ErpOrder.Ord_Number,
  766. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  767. Ordv_DigitalNumber,
  768. Ord_Type,
  769. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  770. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  771. (select Cus_NamePinyin from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 姓名拼音1,
  772. Cus_Name AS 客户姓名,
  773. Cus_Name_py AS 客户拼音,
  774. Cus_Sex_cs AS 客户性别,
  775. Cus_Telephone AS 客户电话,
  776. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  777. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  778. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  779. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  780. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  781. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  782. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  783. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  784. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  785. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  786. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  787. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  788. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  789. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  790. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  791. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期
  792. ,tb_ErpOrderPhotoPrints.ID AS PPID
  793. ,Opps_PhotoName AS 相片名称, Opps_PhotoQuantity AS 数量, Opps_PhotoArea AS 面积,Opps_SendVendor AS 发出状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_SendTime)) AS 发出日期,
  794. dbo.fn_CheckPhotoPrintsReworkStatus(Opps_ReworkStatus) AS 返工状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_ReworkTime)) AS 返工日期,
  795. dbo.fn_CheckProductCompletedStatus(Opps_CompletedStatus) AS 完成状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_CompletedTime)) AS 完成日期
  796. ,Case when (select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  797. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  798. Left Join tb_ErpOrderPhotoPrints on Opps_OrderNumber = Ordv_ViceNumber
  799. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  800. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  801. '
  802. GO
  803. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrintsMonthPrint')
  804. BEGIN
  805. DROP VIEW [dbo].BView_DoorCityPhotosPrintsMonthPrint
  806. END
  807. GO
  808. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrintsMonthPrint]'))
  809. EXEC dbo.sp_executesql @statement = N'
  810. CREATE VIEW [dbo].[BView_DoorCityPhotosPrintsMonthPrint]
  811. AS
  812. SELECT
  813. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop,
  814. dbo.tb_ErpOrderPhotoPrints.ID AS PPID,Ord_Number, Ordv_ViceNumber,
  815. Ordv_DigitalNumber,
  816. Ord_Type,
  817. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  818. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  819. Cus_Name AS 客户姓名,
  820. Cus_Name_py AS 客户拼音,
  821. Cus_Sex_cs AS 客户性别,
  822. Cus_Telephone AS 客户电话,
  823. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber ) else '''' end) AS 拍摄名称,
  824. dbo.tb_ErpOrderPhotoPrints.Opps_PhotoName AS 相片名称, dbo.tb_ErpOrderPhotoPrints.Opps_PhotoQuantity AS 数量,
  825. dbo.tb_ErpOrderPhotoPrints.Opps_PhotoArea AS 面积m2, dbo.tb_ErpOrderPhotoPrints.Opps_SendVendor AS 是否发出,
  826. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderPhotoPrints.Opps_SendTime)) AS 发出日期,
  827. dbo.tb_ErpOrderPhotoPrints.Opps_SendTime AS 发出日期查询,
  828. dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderPhotoPrints.Opps_CompletedStatus) AS 是否完成,
  829. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderPhotoPrints.Opps_CompletedTime)) AS 完成日期,
  830. dbo.tb_ErpOrderPhotoPrints.Opps_CompletedTime AS 完成日期查询
  831. ,(select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber) AS Ord_ViceOrderCount
  832. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  833. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  834. dbo.tb_ErpOrderPhotoPrints ON
  835. dbo.tb_ErpOrderPhotoPrints.Opps_OrderNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  836. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  837. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  838. '
  839. GO
  840. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityRefinedRepair')
  841. BEGIN
  842. DROP VIEW [dbo].BView_DoorCityRefinedRepair
  843. END
  844. GO
  845. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityRefinedRepair]'))
  846. EXEC dbo.sp_executesql @statement = N'
  847. CREATE VIEW [dbo].[BView_DoorCityRefinedRepair]
  848. AS
  849. SELECT
  850. tb_ErpOrder.ID,
  851. dbo.tb_ErpOrder.Ord_DividedShop,
  852. dbo.tb_ErpOrder.Ord_Number,
  853. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  854. Ordv_DigitalNumber,
  855. Ord_Type,
  856. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  857. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  858. Cus_Name AS 客户姓名,
  859. Cus_Name_py AS 客户拼音,
  860. Cus_Sex_cs AS 客户性别,
  861. Cus_Telephone AS 客户电话,
  862. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  863. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  864. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  865. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  866. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  867. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  868. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  869. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  870. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  871. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  872. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  873. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  874. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  875. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期,
  876. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  877. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_RefinementName) AS 精修师,
  878. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修日期,
  879. dbo.tb_ErpOrderDigital.Ordv_RefinementTime AS 精修日期查询,
  880. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  881. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  882. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  883. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  884. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  885. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  886. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  887. '
  888. GO
  889. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityRepairPiece')
  890. BEGIN
  891. DROP VIEW [dbo].BView_DoorCityRepairPiece
  892. END
  893. GO
  894. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityRepairPiece]'))
  895. EXEC dbo.sp_executesql @statement = N'
  896. CREATE VIEW [dbo].[BView_DoorCityRepairPiece]
  897. AS
  898. SELECT
  899. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number,
  900. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  901. Ordv_DigitalNumber,
  902. Ord_Type,
  903. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  904. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  905. Cus_Name AS 客户姓名,
  906. Cus_Name_py AS 客户拼音,
  907. Cus_Sex_cs AS 客户性别,
  908. Cus_Telephone AS 客户电话,
  909. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  910. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  911. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  912. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  913. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  914. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  915. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  916. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  917. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  918. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄日期,
  919. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName) AS 初修师,
  920. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 初修日期,
  921. dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime AS 初修日期查询,
  922. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  923. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  924. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  925. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  926. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  927. (SELECT COUNT(Ordv_ViceNumber) AS Expr1
  928. FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1
  929. WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  930. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  931. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  932. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  933. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  934. '
  935. GO
  936. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePiece')
  937. BEGIN
  938. DROP VIEW [dbo].BView_DoorCityTotakePiece
  939. END
  940. GO
  941. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePiece]'))
  942. EXEC dbo.sp_executesql @statement = N'
  943. CREATE VIEW [dbo].[BView_DoorCityTotakePiece]
  944. AS
  945. SELECT
  946. tb_ErpOrder.ID,
  947. dbo.tb_ErpOrder.Ord_DividedShop,
  948. dbo.tb_ErpOrder.Ord_Number,
  949. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  950. Ordv_DigitalNumber,
  951. Ord_Type,
  952. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  953. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  954. Cus_Name AS 客户姓名,
  955. Cus_Name_py AS 客户拼音,
  956. Cus_Sex_cs AS 客户性别,
  957. Cus_Telephone AS 客户电话,
  958. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  959. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  960. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  961. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  962. (Ord_SeriesPrice - (Case when (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) is null then 0 else (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) end) + (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number)) AS 欠款,
  963. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  964. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  965. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  966. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  967. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  968. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  969. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  970. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  971. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  972. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'' and OPlist_CompletedStatus = ''1'')>0 then ''未完'' else
  973. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'') > 0 then ''未完'' else
  974. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''1'') > 0 then ''OK'' else '''' end )end )end ) AS 是否完成,
  975. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期,
  976. (select top 1 OPlist_PickupTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期查询,
  977. tb_ErpOrderProductList.ID AS OPID,
  978. OPlist_ProdName AS 商品名称,
  979. dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急,
  980. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS 商品取件日期,
  981. OPlist_SendVendor AS 是否发出,
  982. dbo.fn_CheckProductReworkStatus(OPlist_ReworkStatus) AS 是否返工,
  983. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 商品完成状态,
  984. dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 是否取走
  985. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  986. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  987. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  988. Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber
  989. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  990. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  991. '
  992. GO
  993. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthPieces')
  994. BEGIN
  995. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthPieces
  996. END
  997. GO
  998. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthPieces]'))
  999. EXEC dbo.sp_executesql @statement = N'
  1000. CREATE VIEW [dbo].[BView_DoorCityTotakePieceMonthPieces]
  1001. AS
  1002. SELECT
  1003. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, dbo.tb_ErpOrderProductList.ID AS TPID,
  1004. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1005. Ordv_DigitalNumber,
  1006. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1007. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1008. Cus_Name AS 客户姓名,
  1009. Cus_Name_py AS 客户拼音,
  1010. Cus_Sex_cs AS 客户性别,
  1011. Cus_Telephone AS 客户电话,
  1012. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  1013. OPlist_ProdNumber,
  1014. OPlist_ProdName AS 产品名称,
  1015. OPlist_Class,
  1016. (select Sc_ClassName from tb_ErpSystemCategory where Sc_ClassCode = OPlist_Class) AS 商品类别,
  1017. dbo.tb_ErpOrderProductList.OPlist_ProdQuantity AS 数量, dbo.tb_ErpOrderProductList.OPlist_CostPrice AS 制作费用,
  1018. dbo.tb_ErpOrderProductList.OPlist_SendVendor AS 是否发出,
  1019. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_SendTime)) AS 发出日期,
  1020. dbo.tb_ErpOrderProductList.OPlist_SendTime AS 发出日期查询,
  1021. dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderProductList.OPlist_CompletedStatus) AS 是否完成,
  1022. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_CompletedTime)) AS 完成日期,
  1023. dbo.tb_ErpOrderProductList.OPlist_CompletedTime AS 完成日期查询,
  1024. (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber AND OPlist_Type = ''2'') AS Ord_ViceOrderCount
  1025. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1026. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  1027. dbo.tb_ErpOrderProductList ON
  1028. dbo.tb_ErpOrderProductList.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  1029. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1030. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'')
  1031. '
  1032. GO
  1033. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthPiecesNotBack')
  1034. BEGIN
  1035. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthPiecesNotBack
  1036. END
  1037. GO
  1038. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthPiecesNotBack]'))
  1039. EXEC dbo.sp_executesql @statement = N'
  1040. CREATE VIEW [dbo].[BView_DoorCityTotakePieceMonthPiecesNotBack]
  1041. AS
  1042. SELECT
  1043. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type,tb_ErpOrderProductList_1.ID AS PPID, dbo.tb_ErpOrder.Ord_Number,
  1044. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1045. Ordv_DigitalNumber,
  1046. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1047. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1048. Cus_Name AS 客户姓名,
  1049. Cus_Name_py AS 客户拼音,
  1050. Cus_Sex_cs AS 客户性别,
  1051. Cus_Telephone AS 客户电话,
  1052. tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称,
  1053. tb_ErpOrderProductList_1.OPlist_Class,
  1054. (SELECT Sc_ClassName
  1055. FROM dbo.tb_ErpSystemCategory
  1056. WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别,
  1057. tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_CostPrice AS 制作费用,
  1058. tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出,
  1059. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_SendTime)) AS 发出日期,
  1060. tb_ErpOrderProductList_1.OPlist_SendTime AS 发出日期查询,
  1061. dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成,
  1062. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期,
  1063. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList
  1064. WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount
  1065. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1066. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  1067. dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON
  1068. tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  1069. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1070. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'')
  1071. '
  1072. GO
  1073. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthReworkStatistic')
  1074. BEGIN
  1075. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthReworkStatistic
  1076. END
  1077. GO
  1078. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]'))
  1079. EXEC dbo.sp_executesql @statement = N'
  1080. CREATE VIEW [dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]
  1081. AS
  1082. SELECT
  1083. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, tb_ErpOrderProductList_1.ID AS PPID,
  1084. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1085. Ordv_DigitalNumber,
  1086. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1087. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1088. Cus_Name AS 客户姓名,
  1089. Cus_Name_py AS 客户拼音,
  1090. Cus_Sex_cs AS 客户性别,
  1091. Cus_Telephone AS 客户电话,
  1092. tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称,
  1093. tb_ErpOrderProductList_1.OPlist_Class,
  1094. (SELECT Sc_ClassName FROM dbo.tb_ErpSystemCategory WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别,
  1095. tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出,
  1096. dbo.fn_CheckProductReworkStatus(tb_ErpOrderProductList_1.OPlist_ReworkStatus)
  1097. + CASE OPlist_ReworkRemark WHEN '''' THEN '''' ELSE ''/['' + OPlist_ReworkRemark + '']'' END AS 是否返工,
  1098. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_ReworkTime)) AS 返工日期,
  1099. tb_ErpOrderProductList_1.OPlist_ReworkTime AS 返工日期查询,
  1100. dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成,
  1101. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期,
  1102. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList
  1103. WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount
  1104. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1105. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  1106. dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON
  1107. tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  1108. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1109. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'')
  1110. '
  1111. GO
  1112. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_OrderReport')
  1113. BEGIN
  1114. DROP VIEW [dbo].BView_OrderReport
  1115. END
  1116. GO
  1117. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_OrderReport]'))
  1118. EXEC dbo.sp_executesql @statement = N'
  1119. CREATE VIEW [dbo].[BView_OrderReport]
  1120. AS
  1121. SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, tb_ErpOrderDigital_1.Ordv_ViceNumber,
  1122. dbo.tb_ErpOrder.Ord_Class, Ord_Type, Ord_OrderClass,Ordv_DigitalNumber,
  1123. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1124. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1125. Cus_Name AS 客户姓名,
  1126. Cus_Name_py AS 客户拼音,
  1127. Cus_Sex_cs AS 客户性别,
  1128. Cus_Telephone AS 客户电话,
  1129. [Age_String] AS 年龄,
  1130. [Age_Day] AS 天,
  1131. [Age_Year] AS 年,
  1132. dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别,
  1133. dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源,
  1134. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1135. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1136. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1137. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1138. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  1139. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  1140. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_MakeupArtist!= '''' group by Ordpg_MakeupArtist for xml path('''')),1,1,'''')) as 化妆师,
  1141. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄时间,
  1142. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  1143. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  1144. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_EarlyRepairName) AS 初修师,
  1145. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间,
  1146. dbo.fn_CheckOrderEarlyRepairStatus(tb_ErpOrderDigital_1.Ordv_EarlyRepairStatus) AS 初修状态,
  1147. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_FilmSelectionName) AS 选片师,
  1148. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间,
  1149. dbo.fn_CheckOrderFilmSelectionStatus(tb_ErpOrderDigital_1.Ordv_FilmSelectionStatus) AS 选片状态,
  1150. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_DesignerName) AS 设计师,
  1151. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_DesignerTime)) AS 设计时间,
  1152. dbo.fn_CheckOrderDesignerStatus(tb_ErpOrderDigital_1.Ordv_DesignerStatus) AS 设计状态,
  1153. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_RefinementName) AS 精修师,
  1154. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_RefinementTime)) AS 精修时间,
  1155. dbo.fn_CheckOrderRefinementStatus(tb_ErpOrderDigital_1.Ordv_RefinementStatus) AS 精修状态,
  1156. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_LookDesignName) AS 看设计师,
  1157. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_LookDesignTime)) AS 看设计时间,
  1158. dbo.fn_CheckOrderLookDesignStatus(tb_ErpOrderDigital_1.Ordv_LookDesignStatus) AS 看设计状态,
  1159. tb_ErpOrderDigital_1.Ordv_LookDesignClaim AS 看设计要求,
  1160. (case when (select count(OPlist_PickupStatus) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupStatus = ''0'') >0 then ''未取'' else ''OK'' end) AS 取件状态,
  1161. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupTime != null order by OPlist_PickupTime) AS 取件日期,
  1162. dbo.tb_ErpOrder.Ord_Remark AS 备注,
  1163. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrder.Ord_CreateName) AS 录入员,
  1164. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ord_CreateDateTime)) AS 下单日期,
  1165. Ord_CreateDateTime AS 下单日期查询,
  1166. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1167. FROM
  1168. dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON dbo.tb_ErpOrder.Ord_Number = tb_ErpOrderDigital_1.Ordv_Number
  1169. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1170. where Ord_Type <> ''3''
  1171. '
  1172. GO
  1173. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotBack')
  1174. BEGIN
  1175. DROP VIEW [dbo].BView_ProcessMonitorNotBack
  1176. END
  1177. GO
  1178. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotBack]'))
  1179. EXEC dbo.sp_executesql @statement = N'
  1180. CREATE VIEW [dbo].[BView_ProcessMonitorNotBack]
  1181. AS
  1182. SELECT
  1183. tb_ErpOrderProductList.ID AS PID,
  1184. dbo.tb_ErpOrder.ID,
  1185. Ord_DividedShop,
  1186. Ordv_ViceNumber AS Ord_Number,
  1187. Ord_Number AS Ordv_ViceNumber,
  1188. Ordv_DigitalNumber,
  1189. Ord_Type,
  1190. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1191. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1192. Cus_Name AS 客户姓名,
  1193. Cus_Sex_cs AS 客户性别,
  1194. Cus_Telephone AS 客户电话,
  1195. Ord_SeriesName AS 套系名称,
  1196. Ord_SeriesPrice AS 套系价格,
  1197. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1198. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1199. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1200. dbo.fn_CheckPhotoPrintsSendStatus(OPlist_SendStatus) AS 发片状态,
  1201. OPlist_ProdName AS 商品名称,
  1202. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成状态,
  1203. dbo.fn_CheckDateTime(OPlist_ReservationTakeTime) AS 取件日期,
  1204. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1205. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1206. TR_Communicationstatus AS 沟通状态,
  1207. TR_Remark AS 沟通备注, DATEDIFF(day,
  1208. Ordv_DesignerTime, GETDATE()) AS 几天未完,
  1209. (select Count(ID) as DeCount from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_SendStatus = ''1'' and OPlist_CompletedStatus != ''1'') AS Ord_ViceOrderCount
  1210. FROM dbo.tb_ErpOrder
  1211. LEFT JOIN dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1212. Left JOIN dbo.tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_SendStatus = ''1'' and OPlist_CompletedStatus != ''1''
  1213. LEFT JOIN dbo.tempTB_AggregationCustomer ON Ord_Number = GP_OrderNumber
  1214. LEFT JOIN dbo.Vwp_GetLastClientTrackRecord ON TR_CustomerGroupID = Ordv_Number
  1215. WHERE Ord_Class = ''1'' and OPlist_SendStatus = ''1''
  1216. '
  1217. GO
  1218. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotDesign')
  1219. BEGIN
  1220. DROP VIEW [dbo].BView_ProcessMonitorNotDesign
  1221. END
  1222. GO
  1223. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotDesign]'))
  1224. EXEC dbo.sp_executesql @statement = N'
  1225. CREATE VIEW [dbo].[BView_ProcessMonitorNotDesign]
  1226. AS
  1227. SELECT dbo.tb_ErpOrder.ID,
  1228. Ord_DividedShop,
  1229. Ord_Number,
  1230. Ordv_ViceNumber,
  1231. Ordv_DigitalNumber,
  1232. Ord_Type,
  1233. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1234. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1235. Cus_Name AS 客户姓名,
  1236. Cus_Sex_cs AS 客户性别,
  1237. Cus_Telephone AS 客户电话,
  1238. Ord_SeriesName AS 套系名称,
  1239. Ord_SeriesPrice AS 套系价格,
  1240. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1241. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1242. dbo.fn_CheckOrderFilmSelectionStatus(Ordv_FilmSelectionStatus) AS 选片状态,
  1243. dbo.fn_CheckOrderDesignerStatus(Ordv_DesignerStatus) AS 设计状态,
  1244. dbo.fn_CheckUserIDGetUserName(Ordv_ReservationDesignerName) AS 设计师,
  1245. dbo.fn_CheckDateTime(Ordv_ReservationDesignerTime) AS 预定时间,
  1246. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1247. (SELECT TOP (1) dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS Expr1 FROM dbo.tb_ErpOrderProductList WHERE
  1248. (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'') AND (OPlist_PickupTime <> NULL) ORDER BY OPlist_PickupTime) AS 取件日期,
  1249. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1250. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1251. TR_Communicationstatus AS 沟通状态,
  1252. TR_Remark AS 沟通备注,
  1253. DATEDIFF(day, Ordv_FilmSelectionTime, GETDATE()) AS 几天未完
  1254. FROM dbo.tb_ErpOrder
  1255. LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1256. LEFT OUTER JOIN dbo.tempTB_AggregationCustomer ON dbo.tb_ErpOrder.Ord_Number = dbo.tempTB_AggregationCustomer.GP_OrderNumber
  1257. LEFT OUTER JOIN dbo.Vwp_GetLastClientTrackRecord ON dbo.Vwp_GetLastClientTrackRecord.TR_CustomerGroupID = dbo.tb_ErpOrderDigital.Ordv_Number
  1258. WHERE
  1259. dbo.tb_ErpOrder.Ord_Class = ''1'' AND dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus = ''1'' AND dbo.tb_ErpOrderDigital.Ordv_DesignerStatus <> ''2''
  1260. '
  1261. GO
  1262. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotLook')
  1263. BEGIN
  1264. DROP VIEW [dbo].BView_ProcessMonitorNotLook
  1265. END
  1266. GO
  1267. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotLook]'))
  1268. EXEC dbo.sp_executesql @statement = N'
  1269. CREATE VIEW [dbo].[BView_ProcessMonitorNotLook]
  1270. AS
  1271. SELECT
  1272. dbo.tb_ErpOrder.ID,
  1273. Ord_DividedShop,
  1274. Ord_Number,
  1275. Ordv_ViceNumber,
  1276. Ordv_DigitalNumber,
  1277. Ord_Type,
  1278. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1279. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1280. Cus_Name AS 客户姓名,
  1281. Cus_Sex_cs AS 客户性别,
  1282. Cus_Telephone AS 客户电话,
  1283. Ord_SeriesName AS 套系名称,
  1284. Ord_SeriesPrice AS 套系价格,
  1285. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1286. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1287. dbo.fn_CheckOrderDesignerStatus(Ordv_DesignerStatus) AS 设计状态,
  1288. dbo.fn_CheckOrderLookDesignStatus(Ordv_LookDesignStatus) AS 看样状态,
  1289. dbo.fn_CheckUserIDGetUserName(Ordv_ReservationLookDesignName) AS 看样师,
  1290. dbo.fn_CheckDateTime(Ordv_ReservationLookDesignTime) AS 预定时间,
  1291. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1292. (SELECT TOP (1) dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS Expr1 FROM dbo.tb_ErpOrderProductList WHERE
  1293. (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'') AND (OPlist_PickupTime <> NULL) ORDER BY OPlist_PickupTime) AS 取件日期,
  1294. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1295. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1296. TR_Communicationstatus AS 沟通状态,
  1297. TR_Remark AS 沟通备注,
  1298. DATEDIFF(day, Ordv_DesignerTime, GETDATE()) AS 几天未完
  1299. FROM dbo.tb_ErpOrder
  1300. LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1301. LEFT OUTER JOIN dbo.tempTB_AggregationCustomer ON Ord_Number = GP_OrderNumber
  1302. LEFT OUTER JOIN dbo.Vwp_GetLastClientTrackRecord ON
  1303. dbo.Vwp_GetLastClientTrackRecord.TR_CustomerGroupID = dbo.tb_ErpOrderDigital.Ordv_Number
  1304. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderDigital.Ordv_DesignerStatus = ''2'') AND
  1305. (dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus <> ''1'')
  1306. '
  1307. GO
  1308. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotPickup')
  1309. BEGIN
  1310. DROP VIEW [dbo].BView_ProcessMonitorNotPickup
  1311. END
  1312. GO
  1313. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotPickup]'))
  1314. EXEC dbo.sp_executesql @statement = N'
  1315. CREATE VIEW [dbo].[BView_ProcessMonitorNotPickup]
  1316. AS
  1317. SELECT
  1318. tb_ErpOrderProductList.ID AS PID,
  1319. dbo.tb_ErpOrder.ID,
  1320. Ord_DividedShop,
  1321. Ordv_ViceNumber AS Ord_Number,
  1322. Ord_Number AS Ordv_ViceNumber,
  1323. Ordv_DigitalNumber,
  1324. Ord_Type,
  1325. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1326. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1327. Cus_Name AS 客户姓名,
  1328. Cus_Sex_cs AS 客户性别,
  1329. Cus_Telephone AS 客户电话,
  1330. Ord_SeriesName AS 套系名称,
  1331. Ord_SeriesPrice AS 套系价格,
  1332. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1333. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1334. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1335. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成状态,
  1336. OPlist_ProdName AS 商品名称,
  1337. dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 取件状态,
  1338. dbo.fn_CheckDateTime(OPlist_ReservationTakeTime) AS 取件日期,
  1339. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1340. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1341. TR_Communicationstatus AS 沟通状态,
  1342. TR_Remark AS 沟通备注, DATEDIFF(day,
  1343. Ordv_DesignerTime, GETDATE()) AS 几天未完,
  1344. (select Count(ID) as DeCount from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''1'' and OPlist_PickupStatus != ''1'') AS Ord_ViceOrderCount
  1345. FROM dbo.tb_ErpOrder
  1346. LEFT JOIN dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1347. Left JOIN dbo.tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''1'' and OPlist_PickupStatus != ''1''
  1348. LEFT JOIN dbo.tempTB_AggregationCustomer ON Ord_Number = GP_OrderNumber
  1349. LEFT JOIN dbo.Vwp_GetLastClientTrackRecord ON TR_CustomerGroupID = Ordv_Number
  1350. WHERE Ord_Class = ''1'' and OPlist_CompletedStatus = ''1''
  1351. '
  1352. GO
  1353. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotRepair')
  1354. BEGIN
  1355. DROP VIEW [dbo].BView_ProcessMonitorNotRepair
  1356. END
  1357. GO
  1358. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotRepair]'))
  1359. EXEC dbo.sp_executesql @statement = N'
  1360. CREATE VIEW [dbo].[BView_ProcessMonitorNotRepair]
  1361. AS
  1362. SELECT
  1363. tb_ErpOrder.ID,
  1364. Ord_DividedShop,
  1365. Ord_Number,
  1366. Ordv_ViceNumber,
  1367. Ordv_DigitalNumber,
  1368. Ord_Type,
  1369. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1370. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1371. Cus_Name AS 客户姓名,
  1372. Cus_Sex_cs AS 客户性别,
  1373. Cus_Telephone AS 客户电话,
  1374. Ord_SeriesName AS 套系名称,
  1375. Ord_SeriesPrice AS 套系价格,
  1376. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1377. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1378. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  1379. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  1380. dbo.fn_CheckOrderEarlyRepairStatus(Ordv_EarlyRepairStatus) AS 修片状态,
  1381. dbo.fn_CheckUserIDGetUserName(Ordv_ReservationEarlyRepairName) AS 修片师,
  1382. dbo.fn_CheckDateTime(Ordv_ReservationEarlyRepairTime) AS 预定时间,
  1383. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1384. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupTime != null order by OPlist_PickupTime) AS 取件日期,
  1385. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1386. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1387. TR_Communicationstatus AS 沟通状态,
  1388. TR_Remark AS 沟通备注,
  1389. (datediff(day, (select top 1 Ordpg_PhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC), getdate())) AS 几天未完
  1390. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1391. dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1392. left join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber
  1393. Left join dbo.Vwp_GetLastClientTrackRecord on TR_CustomerGroupID = Ordv_Number
  1394. WHERE (Ord_Class = ''1'') and Ordv_EarlyRepairStatus != ''2''
  1395. '
  1396. GO
  1397. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotSelected')
  1398. BEGIN
  1399. DROP VIEW [dbo].BView_ProcessMonitorNotSelected
  1400. END
  1401. GO
  1402. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotSelected]'))
  1403. EXEC dbo.sp_executesql @statement = N'
  1404. CREATE VIEW [dbo].[BView_ProcessMonitorNotSelected]
  1405. AS
  1406. with tb AS
  1407. (
  1408. SELECT dbo.tb_ErpOrder.ID,
  1409. Ord_DividedShop,
  1410. Ord_Number,
  1411. Ordv_ViceNumber,
  1412. Ordv_DigitalNumber,
  1413. Ord_Type,
  1414. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1415. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1416. dbo.tempTB_AggregationCustomer.Cus_Name AS 客户姓名,
  1417. dbo.tempTB_AggregationCustomer.Cus_Sex_cs AS 客户性别,
  1418. dbo.tempTB_AggregationCustomer.Cus_Telephone AS 客户电话,
  1419. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1420. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1421. dbo.fn_GetOrderArrears(dbo.tb_ErpOrder.Ord_Number) AS 欠款,
  1422. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1423. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  1424. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  1425. dbo.fn_CheckOrderFilmSelectionStatus(Ordv_FilmSelectionStatus) AS 选片状态,
  1426. dbo.fn_CheckUserIDGetUserName(Ordv_ReservationFilmSelectionName) AS 选片师,
  1427. dbo.fn_CheckDateTime(Ordv_ReservationFilmSelectionTime) AS 预定时间,
  1428. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1429. (SELECT TOP (1) dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS Expr1 FROM dbo.tb_ErpOrderProductList WHERE (OPlist_ViceNumber = Ordv_ViceNumber) AND OPlist_Type = ''2'' AND OPlist_PickupTime <> NULL ORDER BY OPlist_PickupTime) AS 取件日期,
  1430. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1431. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1432. TR_Communicationstatus AS 沟通状态,
  1433. TR_Remark AS 沟通备注, DATEDIFF(day,
  1434. (SELECT TOP (1) Ordpg_PhotographyTime FROM dbo.tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber AND Ordpg_PhotographyTime IS NOT NULL ORDER BY Ordpg_PhotographyTime DESC), GETDATE()) AS 几天未完
  1435. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1436. dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number LEFT OUTER JOIN
  1437. dbo.tempTB_AggregationCustomer ON
  1438. Ord_Number = GP_OrderNumber LEFT OUTER JOIN
  1439. Vwp_GetLastClientTrackRecord ON
  1440. TR_CustomerGroupID = Ordv_Number
  1441. WHERE Ord_Class = ''1'' and Ordv_FilmSelectionStatus != ''1''
  1442. )
  1443. select * from tb where 拍照状态 = ''OK''
  1444. '
  1445. GO
  1446. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotSelected2')
  1447. BEGIN
  1448. DROP VIEW [dbo].BView_ProcessMonitorNotSelected2
  1449. END
  1450. GO
  1451. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotSelected2]'))
  1452. EXEC dbo.sp_executesql @statement = N'
  1453. CREATE VIEW [dbo].[BView_ProcessMonitorNotSelected2]
  1454. AS
  1455. SELECT tb_ErpOrder.ID,
  1456. Ord_DividedShop,
  1457. Ord_Number,
  1458. Ordv_ViceNumber,
  1459. Ordv_DigitalNumber,
  1460. Ord_Type,
  1461. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1462. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1463. Cus_Name AS 客户姓名,
  1464. Cus_Sex_cs AS 客户性别,
  1465. Cus_Telephone AS 客户电话,
  1466. Ord_SeriesName AS 套系名称,
  1467. Ord_SeriesPrice AS 套系价格,
  1468. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1469. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1470. --dbo.fn_CheckOrderEarlyRepairStatus(Ordv_EarlyRepairStatus) AS 修片状态,
  1471. dbo.fn_CheckOrderFilmSelectionStatus(Ordv_FilmSelectionStatus) AS 选片状态,
  1472. dbo.fn_CheckUserIDGetUserName(Ordv_ReservationFilmSelectionName) AS 选片师,
  1473. dbo.fn_CheckDateTime(Ordv_ReservationFilmSelectionTime) AS 预定时间,
  1474. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1475. (SELECT TOP (1) dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS Expr1 FROM dbo.tb_ErpOrderProductList
  1476. WHERE (OPlist_ViceNumber = Ordv_ViceNumber) AND (OPlist_Type = ''2'') AND (OPlist_PickupTime <> NULL) ORDER BY OPlist_PickupTime) AS 取件日期,
  1477. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1478. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1479. TR_Communicationstatus AS 沟通状态,
  1480. TR_Remark AS 沟通备注,
  1481. DATEDIFF(day, Ordv_EarlyRepairTime, GETDATE()) AS 几天未完
  1482. FROM dbo.tb_ErpOrder
  1483. LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1484. LEFT OUTER JOIN dbo.tempTB_AggregationCustomer ON Ord_Number = GP_OrderNumber
  1485. LEFT OUTER JOIN dbo.Vwp_GetLastClientTrackRecord ON TR_CustomerGroupID = Ordv_Number
  1486. WHERE Ord_Class = ''1'' AND Ordv_EarlyRepairStatus = ''2'' AND Ordv_FilmSelectionStatus <> ''1''
  1487. '
  1488. GO
  1489. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotSend')
  1490. BEGIN
  1491. DROP VIEW [dbo].BView_ProcessMonitorNotSend
  1492. END
  1493. GO
  1494. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotSend]'))
  1495. EXEC dbo.sp_executesql @statement = N'
  1496. CREATE VIEW [dbo].[BView_ProcessMonitorNotSend]
  1497. AS
  1498. SELECT
  1499. tb_ErpOrderProductList.ID AS PID,
  1500. dbo.tb_ErpOrder.ID,
  1501. Ord_DividedShop,
  1502. Ordv_ViceNumber AS Ord_Number,
  1503. Ord_Number AS Ordv_ViceNumber,
  1504. Ordv_DigitalNumber,
  1505. Ord_Type,
  1506. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1507. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1508. Cus_Name AS 客户姓名,
  1509. Cus_Sex_cs AS 客户性别,
  1510. Cus_Telephone AS 客户电话,
  1511. Ord_SeriesName AS 套系名称,
  1512. Ord_SeriesPrice AS 套系价格,
  1513. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1514. (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) as 拍摄名称,
  1515. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1516. dbo.fn_CheckDateTime(Ordv_ReservationSendPhotoTime) AS 预定时间,
  1517. dbo.fn_CheckPhotoPrintsSendStatus(OPlist_SendStatus) AS 发片状态,
  1518. OPlist_ProdName AS 商品名称,
  1519. dbo.fn_CheckDateTime(OPlist_ReservationTakeTime) AS 取件日期,
  1520. TR_TracePersonID AS 客服人员,
  1521. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1522. TR_Communicationstatus AS 沟通状态,
  1523. TR_Remark AS 沟通备注, DATEDIFF(day,
  1524. Ordv_DesignerTime, GETDATE()) AS 几天未完,
  1525. (select Count(ID) as DeCount from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_SendStatus = ''0'') AS Ord_ViceOrderCount
  1526. FROM dbo.tb_ErpOrder
  1527. LEFT JOIN dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1528. Left JOIN dbo.tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_SendStatus = ''0''
  1529. LEFT JOIN dbo.tempTB_AggregationCustomer ON Ord_Number = GP_OrderNumber
  1530. LEFT JOIN dbo.Vwp_GetLastClientTrackRecord ON TR_CustomerGroupID = Ordv_Number
  1531. WHERE Ord_Class = ''1'' and Ordv_LookDesignStatus = ''1''
  1532. '
  1533. GO
  1534. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_ProcessMonitorNotShot')
  1535. BEGIN
  1536. DROP VIEW [dbo].BView_ProcessMonitorNotShot
  1537. END
  1538. GO
  1539. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_ProcessMonitorNotShot]'))
  1540. EXEC dbo.sp_executesql @statement = N'
  1541. CREATE VIEW [dbo].[BView_ProcessMonitorNotShot]
  1542. AS
  1543. SELECT
  1544. tb_ErpOrdersPhotography.ID AS PID,
  1545. tb_ErpOrder.ID,
  1546. Ord_DividedShop,
  1547. Ord_Number,
  1548. Ordv_ViceNumber,
  1549. Ordv_DigitalNumber,
  1550. Ord_Type,
  1551. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1552. dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,
  1553. Cus_Name AS 客户姓名,
  1554. Cus_Sex_cs AS 客户性别,
  1555. Cus_Telephone AS 客户电话,
  1556. Ord_SeriesName AS 套系名称,
  1557. Ord_SeriesPrice AS 套系价格,
  1558. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  1559. Ordpg_Sights as 拍摄名称,
  1560. dbo.fn_CheckPhotographyStatus(Ordpg_PhotographyStatus) AS 拍照状态,
  1561. dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyName) AS 摄影师,
  1562. dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupArtist) AS 化妆师,
  1563. dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationBootDivision) AS 引导师,
  1564. dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime) AS 预定时间,
  1565. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 结婚日期,
  1566. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupTime != null order by OPlist_PickupTime) AS 取件日期,
  1567. dbo.fn_CheckUserIDGetUserName(TR_TracePersonID) AS 客服人员,
  1568. dbo.fn_CheckDateTime(TR_CreateDateTime) AS 录入时间,
  1569. TR_Communicationstatus AS 沟通状态,
  1570. TR_Remark AS 沟通备注,
  1571. (datediff(day, Ord_CreateDateTime, getdate())) AS 几天未完,
  1572. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 WHERE Ordpg_Number = Ordv_Number and Ordpg_PhotographyStatus != ''1'') AS Ord_ViceOrderCount
  1573. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON Ord_Number = Ordv_Number
  1574. Left join dbo.tb_ErpOrdersPhotography on Ordpg_ViceNumber = Ordv_ViceNumber
  1575. left join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber
  1576. Left join dbo.Vwp_GetLastClientTrackRecord on TR_CustomerGroupID = Ordv_Number
  1577. WHERE (Ord_Class = ''1'') and Ordpg_PhotographyStatus != ''1''
  1578. '
  1579. GO